package com.ugoodtech.mdcc.core.repository;

/* Copyright (C) Ugoodtech, Inc - All Rights Reserved.
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 * Written by Stone Shaw.
 */

import com.ugoodtech.mdcc.core.domain.Department;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface DepartmentRepository extends CrudRepository<Department, Long>, QueryDslPredicateExecutor<Department> {

    @Query("from Department where id=:deparmentId and user_id=:userId")
    Department selectDeparmentByUserId(@Param("deparmentId") Long deparmentId, @Param("userId") Long userId);

    @Query("from Department where serialNumber=:code and name=:name and deleted=false and enabled=true")
    Department selectDeparmentByCode(@Param("code") String code, @Param("name") String name);

    @Query("from Department where user_leader_id=:userId and deleted=false and enabled=true")
    Department selectDeparmentLeader(@Param("userId") Long userId);

    @Query("from Department where parent_id=:deparmentId and deleted=false and enabled=true")
    List<Department> selectParentDeparmentL(@Param("deparmentId") Long deparmentId);

    @Query("from Department where name=:name and deleted=false and enabled=true")
    Department selectByName(@Param("name") String name);

    @Query("from Department where parent=null and deleted=false and enabled=true")
    List<Department> getParentDeprtments();


}
